package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.RoleMapper;
import com.itheima.pojo.Result;
import com.itheima.pojo.Role;
import com.itheima.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public Result<Page> selectPage(Page page) {
        // 创建 LambdaQueryWrapper 来构造查询条件
        LambdaQueryWrapper<Role> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();

        // 调用 Mapper 的 selectPage 方法进行分页查询
        Page page1 = roleMapper.selectPage(page, roleLambdaQueryWrapper);
        return Result.success(page1);
    }
    @Override
    public Result<Page> selectPage1(Page page, Integer state) {
        // 创建 LambdaQueryWrapper 来构造查询条件
        LambdaQueryWrapper<Role> roleLambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 添加查询条件，筛选出 state 为 1 的记录
        roleLambdaQueryWrapper.eq(Role::getState, 1);
        // 调用 Mapper 的 selectPage 方法进行分页查询
        Page page1 = roleMapper.selectPage(page, roleLambdaQueryWrapper);
        return Result.success(page1);
    }
}
